<?php
$q=$_GET["q"];
$array= explode(",",$q);
$year=$array[0];
$School_Id=$array[1];
$gra=$array[2];
$hint="";
$nothing="";
$first_option="";
include_once '../Login/databaseconnection.php';
if($year!="Select One"&&$School_Id!=""&&$gra!=""&&$gra!="Select One")
{
$stud=mysql_query("SELECT * FROM students WHERE Grade='$gra' AND School_Id='$School_Id' AND Year='$year'");
if($stud)
{
if($row_stud=mysql_fetch_array($stud))
{
$Gra_Male_Students=$row_stud['No_of_Male'];
$Gra_Female_Students=$row_stud['No_of_Female'];
}
else
{
$Gra_Male_Students='0';
$Gra_Female_Students='0';
}
}
$hint=$hint.'<table height="80" class="imgholder">
           <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Total number of male students:</label>
         </th>
         <td>';
         $hint=$hint."<input type='text' name='Gra_Male_Students' value='$Gra_Male_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Total number of female students:</label>
         </th>
         <td>';
         $hint=$hint."<input type='text' name='Gra_Female_Students' value='$Gra_Female_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <td>
         </td>
         <td>
		 </td>
         </tr>
		 </table>';
$hint=$hint.'<label>Programme Name:</label>';
$hint=$hint."<select name='Student_Programme_Name' id='$School_Id' onChange='get_stu_details(this.value,this.id)' onmouseover='clearpopbox()'>";
$years=mysql_query("SELECT DISTINCT(Programme_Id) FROM programmes WHERE Year='$year' AND School_Id='$School_Id' AND Grade='$gra'");
if($years)
{
while($row_years=mysql_fetch_array($years))
{
$Programme_Id=$row_years['Programme_Id'];
$tra_id=mysql_query("SELECT * FROM programme WHERE Programme_Id='$Programme_Id'");
if($row=mysql_fetch_array($tra_id))
{
$Programme_Name=$row['Programme_Name'];
}
$hint=$hint.'<option value="'.$Programme_Name.'">'.$Programme_Name.'</option>';
$nothing="false";
if(empty($first_option))
{
$first_option=$Programme_Id;
}
}
}
if($nothing!="false")
{
$hint=$hint.'<option value="">No result</option>';
}
$hint=$hint.'</select>';
$prog=mysql_query("SELECT * FROM programmes WHERE Year='$year' AND Programme_Id='$first_option' AND School_Id='$School_Id' AND Grade='$gra'");
if($prog)
{
if($row_prog=mysql_fetch_array($prog))
{
$Gra_Male_Students=$row_prog['No_Of_Male_Students'];
$Gra_Female_Students=$row_prog['No_Of_Female_Students'];
}
}
$hint=$hint.'<div id="stu_year_details">
 <table height="100" class="imgholder">
          <tr>
        <td> </td>
         <td></td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
          <tr>
        <th>        
         <label>Number of male students:</label>
         </th>
         <td>';
        $hint=$hint."<input type='text' name='Gra_Male_Students' value='$Gra_Male_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of female students:</label>
         </th>
         <td>';
        $hint=$hint."<input type='text' name='Gra_Female_Students' value='$Gra_Female_Students' readonly='readonly' onmouseover='clearpopbox()'/>";
$hint=$hint.'</td>
         </tr>
         </table></div>';
}
if($hint=="")
{
if($School_Id=="")
{
$response="<font color='red'>*Please select a school!</font>";
}
$response=$response.'<table height="80" class="imgholder">
           <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
      <tr>
        <th>        
         <label>Total number of male students:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Gra_Male_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Total number of female students:</label>
         </th>
         <td>';
         $response=$response."<input type='text' name='Gra_Female_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
         <tr>
        <td>        
        </td>
         <td></td>
         </tr></table>';
$response=$response.'<label>Programme Name:</label>';
       $response=$response."<select name='Student_Programme_Name' id='$School_Id' onChange='get_stu_details(this.value,this.id)')<option value=''>No result</option>"; 
$response=$response.'</select><div id="stu_year_details">
 <table height="100" class="imgholder">
          <tr>
        <td> </td>
         <td></td>
         </tr>
         <tr>
        <th>        
        </th>
         <td>
        </td>
         </tr> 
          <tr>
        <th>        
         <label>Number of male students:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='Gra_Male_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         <tr>
        <th>        
         <label>Number of female students:</label>
         </th>
         <td>';
        $response=$response."<input type='text' name='Gra_Female_Students' readonly='readonly'/>";
$response=$response.'</td>
         </tr>
         </table></div>';
}
else
{
$response=$hint;
}
echo $response;
?>